﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessLogic;
using JScripter;
using BusinessLogic.Controller;
using DataEntity;

public partial class AjaxPages_User_Registration : AjaxPage
{

    protected override void OnLoad(EventArgs e)
    {
        if (!this.IsAjaxPostBack)
        {
            new LoginTypeController().BindLoginType(ddLoginTypeID);
        }
        base.OnLoad(e);
    }

    private void AddData()
    {
        try
        {
            LoginUser objLoginUser = new LoginUser();

            objLoginUser.LoginID = Guid.NewGuid();

            objLoginUser.Username = HtmlHelper.ControlValue(txtUsername.ClientID);

            objLoginUser.Password = HtmlHelper.ControlValue(txtPassword.ClientID);

            objLoginUser.FirstName = HtmlHelper.ControlValue(txtFirstName.ClientID);

            objLoginUser.LastName = HtmlHelper.ControlValue(txtLastName.ClientID);

            objLoginUser.City = HtmlHelper.ControlValue(txtCity.ClientID);


            objLoginUser.Occupation = HtmlHelper.ControlValue(txtOccupation.ClientID);


            objLoginUser.LoginTypeID = Convert.ToInt32(HtmlHelper.ControlValue(ddLoginTypeID.ClientID));

            objLoginUser.ModifiedDate = DateTime.Now;

            objLoginUser.IsApproved = true;

            objLoginUser.IsDeleted = false;

            new LoginUserController().Add(objLoginUser);
        }
        catch (Exception ex)
        {
            divMessage.InnerHtml = "<div class='error'>" + ex.Message + "</div>";
        }
    }

    public void PreventData()
    {
        txtUsername.Text = HtmlHelper.ControlValue(txtUsername.ClientID);
        txtPassword.Text = HtmlHelper.ControlValue(txtPassword.ClientID);
        txtFirstName.Text = HtmlHelper.ControlValue(txtFirstName.ClientID);
        txtLastName.Text = HtmlHelper.ControlValue(txtLastName.ClientID);
        txtCity.Text = HtmlHelper.ControlValue(txtCity.ClientID);
        txtOccupation.Text = HtmlHelper.ControlValue(txtOccupation.ClientID);
        new LoginTypeController().BindLoginType(ddLoginTypeID, HtmlHelper.ControlValue(ddLoginTypeID.ClientID));
    }



    protected void AddAjaxClick(object sender, AjaxControl.AjaxEventArg e)
    {
        AddData();
        PreventData();
        Response.Redirect("~/College/Ajaxer/CourceCatagoryInfoView.aspx");
    }





}